package Solution101_200.problem118.yanghuisanjiao;

import java.util.ArrayList;
import java.util.List;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/07/18 17:07
 */
public class Solution {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> result=new ArrayList<>();
        for(int i=0;i<numRows;i++){
            List<Integer>  rowResult=new ArrayList<>();
            if(i==0){
                rowResult.add(1);
            }else if(i==1){
                rowResult.add(1);
                rowResult.add(1);
            }else {
                List<Integer> preRow=result.get(i-1);
                for(int j=0;j<=i;j++){
                    if(j==0||j==i){
                        rowResult.add(1);
                    }else {
                        rowResult.add(preRow.get(j-1)+preRow.get(j));
                    }
                }
            }
            result.add(rowResult);
        }
        return result;
    }
}
